<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="layout :: common_header(~{::title})">
    <title>mysql备份-系统设置</title>
</head>
<body th:replace="layout :: common_body(~{::div.layui-body})">

<div class="layui-body" style="padding:15px;">
    <style type="text/css">
        .update {
            display: inline-block;
            margin-left: 15px;
            padding: 0 20px;
            height: 40px;
            line-height: 40px;
            font-size: 14px;
            background: #009789;
            color: #fff;
            text-align: center;
            border-radius: 3px;
            cursor: pointer;
        }

        .update i {
            display: inline-block;
            margin-right: 10px;
            vertical-align: middle;
            width: 30px;
            height: 30px;
            background: url();
        }
    </style>


    <!-- content starts -->
    <blockquote class="layui-elem-quote">MySQL备份</blockquote>

    <fieldset class="layui-elem-field">
        <legend></legend>
        <div class="layui-field-box">
            <div class="layui-form-item" id="import_order" >
                <div class="layui-inline">
                    <form method="post" enctype="multipart/form-data" id="execl_form">
                    
                        <input type="file" name="excel" id="excel" placeholder=""  class="layui-input" style="display:none;">
                        <input type="text" name="path" id="path" placeholder="" th:value="${path}" class="layui-input" style="width:300px">

                    </form>
                </div>

                <div class="layui-inline">
                    <button type="button" id="excel_upload_btn" class="layui-btn layui-btn-primary" style="display: none;">导入Order数据
                    </button>
                    <span id="excel_upload_btn_" style="display: none;" class="update"><i></i>导入中</span>
                </div>
            </div>

            <div class="layui-form-item">

                <form class="layui-form ">
                    <div class="layui-inline">
                        <button type="button" class="layui-btn layui-btn-normal" id="excel_import">备份数据库</button>
                        <span id="excel_import_" style="display: none;" class="update"><i></i>备份中</span>
                    </div>
                    <div class="layui-inline">
                        <a href="JavaScript:;" style="color: red;font-size: large;" id="result"></a>
                    </div>

                </form>
            </div>
        </div>
    </fieldset>

    <!-- start dd-wrapper -->
    <link rel="stylesheet" href="/goods/order.css"/>
    <div class="dd-wrapper">
        <table class="dd-table">
            <tr>
                <th>序号</th>
                <th>文件名</th>
                <th>创建时间</th>

            </tr>
            <tr th:each="item:${backupList}">
                <td th:text="${itemStat.index+1}"></td>
               
                <td th:text="${item.name}"></td>
                <td th:text="${item.time}"></td>

            </tr>
        </table>
    </div>
    <!-- end dd-wrapper -->


    <script type="text/javascript" src="/goods/Tips/Tips.min.js"></script>
    <script type="text/javascript">
        var layer;
        var $;
        var windowOpen;
        var orderList;

        layui.use(['jquery', 'form', 'layer'], function () {

            $ = layui.jquery;
            var form = layui.form;
            layer = layui.layer;

            $(function () {
                //AJAX 上传订单excel
                $("#excel_upload_btn").click(function () {
                    var excel = $("#excel").val();
                    if (excel == '') {
                        alert("请选择文件夹中任一文件");
                        return false;
                    } 
                        var url = "/system/backup_select_ajax";
                        // var formData = new FormData($('#execl_form')[0]);
                    return false;
                })

                //批量导入
                $("#excel_import").click(function () {
                        $("#excel_import_").show();
                        $("#excel_import").hide();
                        $.ajax({
                            url: "/system/backup_mysql_ajax",
                            type: "post",
                            dataType: "JSON",
                            contentType: 'application/json',
                            data:JSON.stringify({path:$("#path").val()}),
                            success: function (result) {
                                $("#excel_import_").hide();
                                $("#excel_import").show();
                                // console.log(result);
                                if (result.code == 0) {
                                    layer.msg("备份成功")
                                    $("#result").text(result.msg)
                                    
                                    // window.location.reload();
                                } else {
                                    layer.msg("执行失败")
                                    $("#result").text(result.msg)
                                }

                                // alert(JSON.stringify(result));
                                return false;
                            }
                        });

                })
            })
        
        });
    </script>



</body>
<html>
